/*
 * FileName: AtomicIntegerArrayDemo.java
 * Author:   zzw
 * Date:     2018年05月17日
 * Description:
 */
package com.zzw.thread;

import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * 〈〉<br>
 * 〈〉
 *
 * @author zzw
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本]（可选）
 */
public class AtomicIntegerArrayDemo {

    private static AtomicIntegerArray array = new AtomicIntegerArray(10);

    public static class AddThread implements Runnable{

        @Override
        public void run() {
            for (int k = 0;k < 10000;k++){
                System.out.println(k % array.length());
                array.getAndIncrement(k % array.length());
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread[] ts = new Thread[10];
        for (int k = 0;k < 10;k++){
            ts[k] = new Thread(new AddThread());
        }
        for (int k = 0;k < 10;k++){
            ts[k].start();
        }
        for (int k = 0;k < 10;k++){
            ts[k].join();
        }
        System.out.println(array);
    }
}
